﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Hotel.NhanVien;

namespace Hotel.NhanVien
{
    public partial class ReportLuongtatcanhanvien : Form
    {
        SqlConnection conn = new SqlConnection("Server=(local);DataBase=Hotel;Integrated Security=SSPI");
        QuanLiLuong qll;
        DateTime begin, end;
        public ReportLuongtatcanhanvien(QuanLiLuong _qll,DateTime _begin, DateTime _end)
        {   
            InitializeComponent();
            this.qll = _qll;
            this.begin = _begin;
            this.end = _end;
        }

        private void ReportLuongtatcanhanvien_Load(object sender, EventArgs e)
        {
           // string ngayend = string.Format("{0:yyyy/MM/dd}", qll.dtpNgayketthuc.Value);
           // string ngaybegin = string.Format("{0:yyyy/MM/dd}", qll.dtpNgaybatdau.Value); 
           // MessageBox.Show("Ngay bat dau " + qll.begin.ToString() + "Ngay ket thuc " + qll.end.ToString());
          
            CrystalReportTongluongnhanvien  rpt = new CrystalReportTongluongnhanvien();
            DataTable dt = null;
            // lấy ngày cuối cùng của 1 tháng (06/30/2012)
            // (SELECT     DATEADD(d, - 1, DATEADD(mm, DATEDIFF(mm, 0, GETDATE()) + 1, 0)) AS NgayCuoiThang)
            string sql = "SELECT dbo.NhanVien.TenNV, dbo.Luong.SoNgayNghi, dbo.Luong.TienUngTruoc, dbo.Luong.NgayPhatLuong, dbo.Luong.TongLuong "
                        + " FROM  dbo.Luong INNER JOIN dbo.NhanVien ON dbo.Luong.MaNV = dbo.NhanVien.MaNV "
                        + " WHERE     (dbo.Luong.DaXoa = 1) "
                                    + "  AND  (dbo.Luong.NgayPhatLuong <= '" +(qll.end) + "' ) "
                                    + "  AND (dbo.Luong.NgayPhatLuong >= '"+qll.begin+"') ";
                         
           try
            {
                conn.Open();
                SqlDataAdapter da = new SqlDataAdapter(sql, conn);
                dt = new DataTable();
                da.Fill(dt);
                rpt.SetDataSource(dt);
                rpt.Refresh();
                baocaoluongtatcanhanvien.ReportSource = rpt;
                baocaoluongtatcanhanvien.Refresh();
            }
            catch (Exception ev)
            {
                MessageBox.Show(ev.Message);

            }
            finally
            {
                conn.Close();
            }
        }
    }
}
